<template>
  <div>
    <section>
      <el-card>
        <el-button
          type="primary"
          :loading="loading"
          size="default"
          v-auth="'/sys/setting/update'"
          @click="save"
          style="margin-bottom: 10px;"
        >
          {{ $t('operation.save') }}
        </el-button>
        <div class="-editor">
          <text-editor v-model="formParams.contentEn" />
        </div>
      </el-card>
    </section>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, reactive } from 'vue'
import { settingGetInfo, updateContent } from '@/api/system/setting'
import { ElMessage } from 'element-plus'
import Editor from '@tinymce/tinymce-vue'

let $emit = defineEmits(['refresh'])

const defaultForm = {
  id: '',
  contentEn: '',
  contentCn: '',
}
let formParams = reactive<any>({
  ...defaultForm,
})
const rules = {
}

onMounted(async () => {
  let { data, status } = await settingGetInfo()
  if (status == 200) {
    Object.keys(formParams).forEach((key) => {
      formParams[key] = data[key]
    })
  }
})

let loading = ref(false)
//保存按钮的方法
const save = async () => {
  loading.value = true
  let result = await updateContent({...formParams, contentCn: formParams.contentEn})
  loading.value = false
  if (result.status == 200) {
    ElMessage({
      type: 'success',
      message: '操作成功',
    })
    $emit('refresh')
  } else {
    ElMessage({
      type: 'error',
      message: '操作失败',
    })
  }
}
</script>

<style scoped>
</style>
